Zhiyong Zhang's Psychometric Website
 
Home Control Panel Login Register Search Submit Logout About me Contact me
My Research
Google
Web
This Site
Home > The R function to simulate data for the direct autoregressive factor score model
The R function to simulate data for the direct autoregressive factor score model
2006-11-17    Zhang, Z.       Read: 10447 times
Cite this page: Zhang, Z. (2006). The R function to simulate data for the direct autoregressive factor score model. Retrieved November 24, 2024, from https://www.psychstat.org/us/article.php/67.htm.
The R function to simulate data for the direct autoregressive factor score model

dafsar1<-function(n){
library(mvtnorm)

y<-array(,dim=c(6,n))
e<-array(,dim=c(6,n))

f<-array(,dim=c(2,n))
v<-array(,dim=c(2,n))

#parameter:
f0<-array(c(0,0),dim=c(2,1))

h<-array(c(1,1,1,0,0,0,
           0,0,0,1,1,1),dim=c(6,2))

fp<-array(c(.8,0,0,.8),dim=c(2,2))
r<-array(c(1,0,0,0,0,0,
           0,1,0,0,0,0,
           0,0,1,0,0,0,
           0,0,0,1,0,0,
           0,0,0,0,1,0,
           0,0,0,0,0,1),dim=c(6,6))
qq<-array(c(.36,.18,.18,.36),dim=c(2,2))

for (i in 1:n){
   v[,i]=t(rmvnorm(1,c(0,0),qq))
   f[,i]=fp%*%f0+v[,i]
   e[,i]=t(rmvnorm(1,c(0,0,0,0,0,0),r))
   y[,i]=h%*%f[,i]+e[,i]
   f0<-f[,i]
}
return(list(y=t(y)[1001:n,],f=t(f)[1001:n,],v=t(v)[1001:n,],e=t(e)[1001:n,]))
}

Submitted by: johnny
Add a comment View comment Add to my favorite Email to a friend Print
If you want to rate, please login first, or click here to register. Or you can use USERNAME: guest and PASSWORD: guest to log in.
Average score 0, based on 0 comments
1 2 3 4 5 6 7 8 9 10
Copyright © 2003-13 Zhiyong Zhang \'s Psychometric Website
Maintained by Zhiyong Zhang